package at.fhooe.mc.master.clc.client.presenter;

import at.fhooe.mc.master.clc.client.MetricsVisualizationEventBus;
import at.fhooe.mc.master.clc.client.view.IAbstractGraphView;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;

//@Presenter(view = AbstractGraphView.class, multiple = true)
public abstract class AbstractGraphPresenter<V extends IAbstractGraphView, E extends MetricsVisualizationEventBus>
		extends AbstractKeyPresenter<V, E>
{
	
	
//	protected String graphTitle = "";
	
	private String type;

	private String jsonDataTable;
	private String title;
	private String axisTitle;

	public String getJsonDataTable()
	{
		return jsonDataTable;
	}

	public void setJsonDataTable(String jsonDataTable)
	{
		this.jsonDataTable = jsonDataTable;
	}

	public String getType()
	{
		return type;
	}

	public void setType(String type)
	{
		this.type = type;
	}
	
	public String getTitle()
	{
		return title;
	}
	
	public String getAxisTitle()
	{
		return axisTitle;
	}
	
	public void setTitle(String title)
	{
		this.title = title;
	}
	
	public void setAxisTitle(String axisTitle)
	{
		this.axisTitle = axisTitle;
	}

	@Override
	public void bind()
	{
		// super.bind();

		if (getJsonDataTable() != null)
		{
			view.setKey(getKey());
			view.setGraph(getJsonDataTable(), getTitle(), getAxisTitle());
			view.getRemoveButton().addClickHandler(new ClickHandler()
			{

				@Override
				public void onClick(ClickEvent event)
				{
					eventBus.removeGraph(view, getKey());
				}
			});

			eventBus.addGraph(view, getKey());
		}
	}

}
